package com.jqq.threaduse.homework;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class Homework02 {
    public static void main(String[] args) {
        Card card = new Card();
        new Thread(card).start();
        new Thread(card).start();
    }
}
class Card implements Runnable{
    private int total = 10000;

    @Override
    public void run() {
        while (true) {
            synchronized (this){
                if(total < 1000) {
                    System.out.println("余额不足，不能取钱了。");
                    break;
                }
                total -= 1000;
                System.out.println(Thread.currentThread().getName() + "取走1000" +
                        "余额=" + (total));
                //休眠50ms
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}